package com.zzq.controller;

import com.zzq.result.SmileResult;
import com.zzq.domain.dto.SmileAlbumDTO;
import com.zzq.service.AlbumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/photographer/album")
@Api(value = "相册图片控制接口", tags = {"相册图片控制接口"})
public class AlbumPhototController {

    @Autowired
    AlbumService albumService;

    @PostMapping("/add")
    @ApiOperation("新增相册")
    public SmileResult addAlbum(@RequestBody SmileAlbumDTO smileAlbumDTO) {

        return albumService.addAlbumPhoto(smileAlbumDTO);
    }

    /**
     *
     * @param file  分片数据
     * @param chunkIndex 当前分片编号
     * @param totalChunks 总分片数
     * @param uploadId oss分片上传唯一标识
     * @param photoId 图片id
     * @param allUrl //上传目录
     * @param albumId // 相册id
     * @return
     * @throws IOException
     */
    @PostMapping("/photot/add")
    @ApiOperation("添加一张图片")
    public SmileResult addPhotoOne(@RequestParam("file") MultipartFile file,
                                   @RequestParam("chunkIndex") Integer chunkIndex,
                                   @RequestParam("totalChunks") Integer totalChunks,
                                   @RequestParam("uploadId") String uploadId,
                                   @RequestParam("photoId") String photoId,
                                   @RequestParam("allUrl") String allUrl,
                                   @RequestParam("albumId") Long albumId) throws IOException {
        return albumService.uploadPricePhoto(file, chunkIndex,totalChunks,albumId,uploadId,Long.valueOf(photoId),allUrl);
    }

    /**
     * 获取唯一oss分片上传标识
     * @param filetype
     * @return
     */
    @GetMapping("/uploadid")
    public SmileResult getUploadId(@RequestParam("albumId")Long albumId,@RequestParam("filetype")String filetype){
        return  albumService.getUploadId(albumId,filetype);
    }


}
